<%@ page contentType="text/html; charset=UTF-8"%>
<%@page import="edu.ccut.saturn.component.SaturnData"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="/extjs/include/all.jsp"%>
<script type="text/javascript" src="${pageContext.request.contextPath}/extjs/js/validate.js"></script>
<title></title>
<script type="text/javascript">
	var userId = '${__SATURN_AUTORITY_USER__.id}';
	var depId = '${__SATURN_AUTORITY_USER__.dep_id}';
	var userName = '${__SATURN_AUTORITY_USER__.username}';
	Ext.onReady(function(){
		Ext.QuickTips.init();
		var resultWidth = Ext.get("process-grid").getWidth();
		var store = new Ext.data.JsonStore({
		    url: '${pageContext.request.contextPath}/edu.ccut.saturn.workflow.client::/startProcessModule/action/QueryStartProList.action',
		    root: 'result',
		    totalProperty:'count',
		    labelWidth:resultWidth*0.1,
		    fields: [
	               {name: 'process_xml_key', mapping: 'process_xml_key'},
	               {name: 'process_define_id', mapping: 'process_define_id'},
	               {name: 'name', mapping: 'name'},
		    	   {name: 'version', mapping: 'version'},
		    	   {name: 'description', mapping: 'description'},
	               {name: 'author', mapping: 'author'},
	               {name: 'update_time', mapping: 'update_time'}
	               ]
		});
	  
	    var grid = new Ext.grid.GridPanel({
       	    store: store,
       	    renderTo:'process-grid',
	        frame:true,
	        title:'启动流程列表',
	        height:600,
	        loadMask: {msg:'正在加载数据，请稍侯……'}, 
	        bodyStyle:'width:100%',
	        columns: [
	       	    {header: "选择", width: resultWidth*0.1, dataIndex: 'process_xml_key', sortable: false,renderer:showOp},
	            {header: "业务流程名称", width: resultWidth*0.3, dataIndex: 'name', sortable: true},
	            {header: "流程版本号", width: resultWidth*0.2, dataIndex: 'version', sortable: true},
	            {header: "流程创建者", width: resultWidth*0.2, dataIndex: 'author', sortable: true},
	            {header: "最后修改时间", width: resultWidth*0.2, dataIndex: 'update_time', sortable: true}
	        ],
	      
	        bbar: new Ext.PagingToolbar({ 
		            pageSize: 20, 
		            store: store, 
		            displayInfo: true, 
		            displayMsg: '当前显示 {0} - {1}条记录 /共 {2}条记录',
		            emptyMsg: "没有数据显示" 
		    }) 
    });
   
   	store.load({params: {start:0,limit:20}});
   	
   	function showOp(value,cellmeta,record){	
   			var name = record.get("name");
   			var description = record.get("description");
   			var process_xml_key = record.get("process_xml_key");
   			var process_define_id = record.get("process_define_id");
			return "<a href=javascript:doStart(\'"+name+"\',\'"+description+"\',\'"+process_xml_key+"\',\'"+process_define_id+"\')>"+"启动"+"</a>";	
	}		
});

	function doStart(name,description,process_xml_key,process_define_id){
		 var panel = new Ext.FormPanel({
		 	frame:true,
		 	layout:'form',
		 	items:[{
                   xtype:'textfield',
                   fieldLabel:'流程实例名称',
                   name:'name',
                   id:'name',
                   value:name,
                    vtype:'isNumberAlphaUnderlineChinese',
		            msgTarget:'qtip',
                   width:200                  
               },{
                   xtype:'textfield',
                   fieldLabel:'流程实例描述',
                   name:'description',
                   id:'description',
                   value:description,
                   vtype:'isNumberAlphaUnderlineChinese',
		           msgTarget:'qtip',
                   width:200
               },{
                   xtype:'textfield',
                   name:'process_define_id',
                   id:'process_define_id',
                   fieldLabel:'流程定义ID',
                   value:process_define_id,
                   disabled:true,
                     width:200
               },{
                   xtype:'textarea',
                   name:'process_xml_key',
                   id:'process_xml_key',
                   fieldLabel:'流程定义名称',
                   value:process_xml_key,
                   disabled:true,
                   width:350
               }],
             buttons: [{
	            text: '确认',
	            handler:function(){
	                var name = Ext.get("name").dom.value;
	                var description = Ext.get("description").dom.value;
	                var process_xml_key = Ext.get("process_xml_key").dom.value;
	                var process_define_id = Ext.get("process_define_id").dom.value;
	                 if(panel.form.isValid()){
			                window.close();  
			            	Ext.Ajax.request({
							     method : 'POST',                             
							     url: '${pageContext.request.contextPath}/edu.ccut.saturn.workflow.client::/startProcessModule/action/StartProcess.action', 
							     success:function(request){            
							       var myResult = Ext.util.JSON.decode(request.responseText);
							       Ext.Msg.alert('信息',myResult.message); 		          
							     },
							     failure:function(){    
							       Ext.Msg.alert("错误", "与后台联系的时候出现了问题");
							     },
							     params:{
							     		wf_name:name, 
							     		wf_description:description, 
							     		wf_process_xml_key:process_xml_key,
							     		wf_creator_name:userName,
							     		wf_creator_department:depId,
							     		wf_process_define_id:process_define_id,
							     		wf_creator:userId
							     } 
					     	});
			            }
			         }
       		 },{
	            text: '重置',
	            handler:function(){
	            	panel.getForm().reset();
	            }
	        }]
         });
        
         var window = new Ext.Window({
            title: '新建启动流程表单',
			width: 500,
			height:300,
			layout: 'fit',
			plain:true,
			items:panel,
			buttonAlign:'center',
			modal:true
           });
           
		window.show();
	    
	    Ext.get('name').dom.maxLength = 16;
		Ext.get('description').dom.maxLength = 16;
	}
</script>
<form></form>
<div id='process-grid' width='100%'></div>
</head>
</html>